package com.itheima.health.service;
import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "检查组模块管理")
public class CheckGroupController {

    @Reference
    private CheckGroupService  checkGroupService;

    @PostMapping("checkgroup/findPage")
    @ApiOperation(value = "分页查询",notes = "根据客户端请求，完成分页查询")//   添加业务方法上
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前分页页码",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="queryString",value="查询条件",required=false,paramType="form",dataType="String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return   new Result(checkGroupService.findPage(queryPageBean)); //   total  +  List
    }

    //添加或者修改检查组的数据
    @GetMapping("checkgroup/updateCheckGroupById/{id}")
    public Result updateCheckGroupById(@PathVariable("id") Integer id ){
        return new Result(checkGroupService.updateCheckGroupById(id));
    }


    //添加或者修改检查组的数据
    @PostMapping("checkgroup/add")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO ){
        checkGroupService.saveCheckGroup(checkGroupDTO);
       return  new Result(true);
    }


    //删除数据
    @DeleteMapping("checkgroup/deleteCheckGroupById/{id}")
    public Result deletePageById(@PathVariable("id") int id){
       return new Result(checkGroupService.updateItemGroupById(id));
    }



    //查询所有检查组的信息
    @GetMapping("checkgroup/findAll")
    @ApiOperation(value = "查询检查组方法", notes = "查询所有的检查组列表信息")
    public Result findAll(){
        return   new Result(checkGroupService.list());
    }
}
